def reverse_labels(input_file, output_file):
    with open(input_file, 'r', encoding='utf-8') as file:
        lines = file.readlines()

    reversed_lines = []
    for line in lines:
        parts = line.split('\t', 1) # 使用tab作为分隔符，确保正确分割标签和其他文本
        if len(parts) == 2:
            label, text = parts
            # 反转标签：如果标签是'1'，则变为'0'；如果是'0'，则变为'1'
            new_label = '0' if label.strip() == '1' else '1'
            reversed_lines.append(f"{new_label}\t{text}")
        else:
            print(f"无法解析行: {line}")

    # 将反转后的数据写入新的文件
    with open(output_file, 'w', encoding='utf-8') as file:
        for line in reversed_lines:
            file.write(line)

# 调用函数，这里指定了您的实际文件名
reverse_labels('./weibo_mini_tsv/test.tsv', './weibo_mini_tsv/test1.tsv')